import { useRouter } from 'vue-router'
import { RouterName } from '@/router/name'

export function useToHome() {
  const router = useRouter()
  const gotoHomePage = async () => {
    await router.push({ name: RouterName.Home })
  }

  const goBack = async () => {
    const state: { back: null | string; [key: string]: any } = globalThis.history.state
    state.back !== null ? router.back() : await gotoHomePage()
  }

  return {
    gotoHomePage,
    goBack
  }
}
